package helper

import "github.com/gin-gonic/gin"

// ===================================响应封装===================================
func Success(c *gin.Context, msg string, data any) {
	if msg == "" {
		msg = "success"
	}
	Result(c, 1, 1, msg, data, 200)
}

func Fail(c *gin.Context, msg string, data any) {
	if msg == "" {
		msg = "fail"
	}
	Result(c, 0, 1, msg, data, 200)
}

func Data(c *gin.Context, data any) {
	Result(c, 1, 0, "success", data, 200)
}

func Result(c *gin.Context, code int, show int, msg string, data any, httpStatus int) {
	if data == nil {
		data = []gin.H{}
	}
	if httpStatus == 0 {
		httpStatus = 200
	}
	c.JSON(httpStatus, gin.H{
		"code": code,
		"msg":  msg,
		"show": show,
		"data": data,
	})
}

// ===================================响应封装===================================
